﻿@using Masuit.MyBlogs.Core.Models.Entity
@using Masuit.Tools.Core.Net
@using Masuit.Tools.Security
@using Masuit.MyBlogs.Core.Configs
@using Masuit.MyBlogs.Core.Common
@using Masuit.Tools.Systems
@using System.Text.RegularExpressions
@model Masuit.MyBlogs.Core.Models.Entity.Post

@if (!string.IsNullOrEmpty(Model.ProtectContent)&&Model.ProtectContentMode==ProtectContentMode.AuthorizeVisiable)
{
    <div class="row protected-content" id="@SnowFlake.NewId">
        @if (!string.IsNullOrEmpty(Context.Session.Get<string>("AccessViewToken")) || Context.Request.Cookies["Email"].MDString3(AppConfig.BaiduAK).Equals(Context.Request.Cookies["PostAccessToken"]))
        {
            <p class="text-red text-center size20">↓↓↓以下是文章加密部分↓↓↓</p>
            @Html.Raw(await Model.ProtectContent.ReplaceImgAttribute(Model.Title))
        }
        else
        {
            <p class="text-red text-center size24 margin-bot10">↓↓↓恭喜你发现镇站之宝，请注意，前方高能！非战斗人员请及时撤离，这不是演习！↓↓↓</p>
            <div class="col-md-12">
                <span class="text-red">以下内容已经隐藏，请输入验证码后查看</span>
                <span class="text-green">【完全免费，不收一分钱】</span>
                <form action="/" method="post" class="form-inline" id="code-token">
                    @Html.AntiForgeryToken()
                    <div class="input-group">
                        <span class="input-group-addon">邮箱：</span>
                        <input type="email" name="Email" id="email3" class="form-control" />
                        <span class="input-group-btn">
                            <button type="button" class="btn btn-info getcode">获取验证码</button>
                        </span>
                    </div>
                    <div class="input-group">
                        <span class="input-group-addon">验证码：</span>
                        <input type="text" name="token" id="token" class="form-control" />
                        <span class="input-group-btn">
                            <button type="submit" class="btn btn-info">查看文章</button>
                        </span>
                    </div>
                </form>
                <p class="text-green">温馨提示：<span class="text-red">获取密码后本站所有加密文章将永久开放！请确保您的邮箱已经通过站长的登记，如果您未使用邮箱登记，请先联系站长获取文章密码并登记邮箱即可！</span></p>
            </div>
        }
    </div>
}
@if (!string.IsNullOrEmpty(Model.ProtectContent)&&Model.ProtectContentMode==ProtectContentMode.CommentVisiable)
{
    <div class="row protected-content">
        @if (string.IsNullOrEmpty(Context.Request.Cookies["Comment_" + Model.Id]))
        {
            <p class="text-red text-center size24 margin-bot10">此处内容回复后刷新页面可见</p>
        }
        else
        {
            @Html.Raw(await Model.ProtectContent.ReplaceImgAttribute(Model.Title))
        }
    </div>
}
@if (!string.IsNullOrEmpty(Model.ProtectContent)&&Model.ProtectContentMode==ProtectContentMode.Password)
{
    <div class="row protected-content">
        @if (Context.Request.Query["password"]!=Model.ProtectPassword)
        {
            <p class="text-red text-center size24 margin-bot10">此处内容需要密码可见：</p>
            <form method="get" enctype="multipart/form-data" class="form-inline">
                <div class="input-group">
                    <span class="input-group-addon">密码：</span>
                    <input class="form-control" type="text" name="password">
                    <input type="hidden" name="t" value="@SnowFlake.NewId">
                    <span class="input-group-btn">
                        <button class="btn btn-info" type="submit">确定</button>
                    </span>
                </div>
            </form>
        }
        else
        {
            @Html.Raw(await Model.ProtectContent.ReplaceImgAttribute(Model.Title))
        }
    </div>
}
@if(Model.ProtectContentMode==ProtectContentMode.Regions) {
    if (Model.ProtectContentLimitMode==RegionLimitMode.AllowRegion&&Regex.IsMatch(Context.Request.Location(),Model.ProtectContentRegions)) {
        @Html.Raw(await Model.ProtectContent.ReplaceImgAttribute(Model.Title))
    }
    if (Model.ProtectContentLimitMode==RegionLimitMode.ForbidRegion&&!Regex.IsMatch(Context.Request.Location(),Model.ProtectContentRegions)) {
        @Html.Raw(await Model.ProtectContent.ReplaceImgAttribute(Model.Title))
    }
}